Skip to content

[minor] Implement Redis-Based Distributed Locking for GitOps Operations#2189

Merged
whitfiea merged 38 commits intomasterfrom
mascore-13109-branch-lock
Apr 21, 2026
Merged

[minor] Implement Redis-Based Distributed Locking for GitOps Operations#2189
whitfiea merged 38 commits intomasterfrom
mascore-13109-branch-lock

Conversation

@Hardik-Prajapati-10
Copy link
Copy Markdown
Contributor

@Hardik-Prajapati-10 Hardik-Prajapati-10 commented Apr 16, 2026

Issue

https://jsw.ibm.com/browse/MASCORE-13109

Description

This PR implements a comprehensive Redis-based distributed locking mechanism to replace the legacy Git branch-based locking system for GitOps operations. The change addresses critical issues with concurrent pipeline executions that previously caused race conditions, merge conflicts, and branch pollution.

Key Changes

1. Redis Locking Infrastructure (image/cli/mascli/functions/gitops_utils)

  • Added Redis connection management with TLS support
  • Implemented atomic lock acquisition using Redis SET NX operations
  • Added lock release with ownership verification using Lua scripts
  • Included automatic lock expiry (TTL) to prevent orphaned locks
  • Added comprehensive retry logic with configurable parameters
  • Default behavior: GITOPS_USE_REDIS_LOCKING=false (Git branch locking) to avoid breaking changes
  • Opt-in Redis: Set GITOPS_USE_REDIS_LOCKING=true to enable Redis locking (fails if Redis unavailable)

2. Container Image Updates

  • Added redis-cli installation script (image/cli/install/install-redis-cli.sh)
  • Updated Dockerfile to include redis-cli in the CLI container image (v19.6.1+)
  • Supports multiple package managers (microdnf, dnf, yum, apt-get, apk)

3. Migrated GitOps Functions (10 functions)

All functions now support gitops_lock_and_modify with Redis locking (opt-in):

  • gitops_cp4d_service
  • gitops_suite_app_config
  • gitops_deprovision_app_config
  • gitops_mas_config
  • gitops_suite_workspace
  • gitops_deprovision_suite_workspace
  • gitops_deprovision_cp4d_service
  • gitops_db2u_database
  • gitops_rds_db2_database
  • gitops_deprovision_db2u_database

4. Documentation

  • Comprehensive setup guide (docs/redis-locking-setup.md)
  • IBM Toolchain configuration script (docs/ibm-toolchain-redis-setup.sh)
  • Migration examples and troubleshooting guide

Impact

Reliability Improvements (when Redis enabled):

  • Eliminates race conditions through atomic Redis operations
  • Prevents merge conflicts in concurrent updates
  • Removes temporary Git branch pollution
  • Automatic lock expiry prevents orphaned locks
  • Explicit control: fails immediately if Redis is unavailable when enabled

Non-Breaking Change:

  • Default: GITOPS_USE_REDIS_LOCKING=false uses existing Git branch locking
  • Opt-in: Set GITOPS_USE_REDIS_LOCKING=true to enable Redis locking
  • Redis is optional - existing deployments continue to work without changes
  • When Redis enabled, it is required (no fallback to Git)
  • Operations fail immediately if Redis is unavailable when explicitly enabled

Test Results

Manual Testing

  • ✅ Redis connection validation with TLS
  • ✅ Lock acquisition and release operations
  • ✅ Concurrent pipeline execution without conflicts
  • ✅ Lock TTL expiry behavior
  • ✅ Retry logic under contention
  • ✅ All 10 migrated GitOps functions tested
  • ✅ Default behavior (Git locking) unchanged
  • ✅ Error handling when Redis enabled but unavailable

Integration Testing

  • ✅ IBM Cloud Redis instance connectivity
  • ✅ IBM Toolchain pipeline execution
  • ✅ Multi-pipeline concurrent operations
  • ✅ Error handling for Redis unavailability
  • ✅ Backward compatibility with existing deployments

Configuration Testing

  • ✅ TLS certificate handling
  • ✅ Authentication (username/password)
  • ✅ Environment variable configuration
  • ✅ Setup script validation (ibm-toolchain-redis-setup.sh)
  • ✅ Default behavior without Redis configuration

Backporting

Related Pull Requests

https://github.ibm.com/maximoappsuite/saas-deploy-py/pull/262


⚠️ Notes for Reviewers

  • Ensure you have understood the guidelines before proceeding with a review.
  • Ensure all sections in the PR template are appropriately completed.
  • Non-breaking change: Default behavior (GITOPS_USE_REDIS_LOCKING=false) maintains existing Git branch locking
  • Opt-in feature: Redis locking requires explicit GITOPS_USE_REDIS_LOCKING=true
  • Explicit control: When Redis enabled, operations fail if Redis unavailable (no silent fallback)
  • Review the migration strategy in docs/redis-locking-setup.md
  • Verify the setup script docs/ibm-toolchain-redis-setup.sh for IBM Cloud integration
  • Check that all 10 migrated functions follow the new locking pattern consistently
  • Validate error handling for Redis unavailability scenarios
  • Review security aspects: TLS configuration, credential handling, and password masking
  • Confirm backward compatibility for existing deployments without Redis

@Hardik-Prajapati-10 Hardik-Prajapati-10 requested a review from a team as a code owner April 16, 2026 09:28
@whitfiea whitfiea changed the title Implement Redis-Based Distributed Locking for GitOps Operations [major] Implement Redis-Based Distributed Locking for GitOps Operations Apr 17, 2026
Comment thread image/cli/Dockerfile Outdated
Comment thread docs/redis-locking-setup.md Outdated
Comment thread docs/redis-locking-setup.md Outdated
Comment thread docs/redis-locking-setup.md Outdated
clarify that Redis env vars must be set whenever migrated GitOps functions are executed, not only in IBM Toolchain
note that IBM Toolchain is optional and document pipeline environment properties as one way to provide runtime variables
remove the custom CLI image/container setup section because custom CLI images are not supported
Comment thread docs/redis-locking-setup.md Outdated
Comment thread image/cli/mascli/functions/gitops_utils Outdated
Comment thread image/cli/mascli/functions/gitops_utils Outdated
… updated behavior to error when Redis is unavailable with explicit Redis locking enabled.
@whitfiea whitfiea changed the title [major] Implement Redis-Based Distributed Locking for GitOps Operations [minor] Implement Redis-Based Distributed Locking for GitOps Operations Apr 21, 2026
@whitfiea whitfiea merged commit 835ca7c into master Apr 21, 2026
14 checks passed
@whitfiea whitfiea deleted the mascore-13109-branch-lock branch April 21, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants